package com.jishuo.base.bean;

import com.github.pagehelper.Page;
import lombok.Data;

import java.util.List;

/**
 * 分页表格返回数据
 */
@Data
public class GridResult<T> {
    private int page;
    private long total;
    private List<T> rows;

    public GridResult() {}

    /**
     * 通过分页对象构建
     * @param rows<
     */
    public GridResult(List<T> rows) {
        if (rows instanceof Page) {
            Page<T> page = (Page<T>)rows;
            this.total = page.getTotal();
            this.page = page.getPageNum();
            this.rows = page.getResult();
        } else {
            this.rows = rows;
            this.total = rows.size();
            this.page = 1;
        }
    }
}
